package com.cby.leetcode.链表.LC141;

public class LC141 {

    /**
     * 链表是否有环
     * 快慢指针？
     *
     * @param args
     */

    public static void main(String[] args) {}

    class ListNode {
        int val;
        ListNode next;
    }


    class Solution {
        public boolean hasCycle(ListNode head){
            ListNode fast = head;
            ListNode slow = head;

            //对快指针以及其next判空即可，快于slow
            while(fast != null && fast.next != null){
                fast = fast.next.next;
                slow = slow.next;
                if(slow == fast)
                    return true;
            }

            return false;
        }
    }

}
